package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderReportVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@ApiOperation("管理端-订单相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PutMapping("/cancel")
    @ApiOperation("管理端-订单取消")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("订单取消{}",ordersCancelDTO);
        orderService.orderCancel(ordersCancelDTO);
        return Result.success();
    }

    @GetMapping("/statistics")
    @ApiOperation("管理端-各个状态订单统计")
    public Result<OrderStatisticsVO> getStatis(){
        log.info("各个状态订单统计");
        OrderStatisticsVO orderStatistics = orderService.getOrderStatistics();
        return Result.success(orderStatistics);
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("管理端-订单完成")
    public Result completeOrder(@PathVariable Long id){
        log.info("订单完成{}",id);
        orderService.orderComplete(id);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("管理端-拒单")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单{}",ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    @ApiOperation("管理端-接单")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单{}",ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    @GetMapping("/details/{id}")
    @ApiOperation("管理端-获取订单信息")
    public Result<OrderVO> getDetails(@PathVariable("id") Long id){
        log.info("获取订单详情{}",id);
        OrderVO orderDetail = orderService.getOrderDetail(id);
        return Result.success(orderDetail);
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("管理端-派送订单")
    public Result deliveryOrder(@PathVariable("id") Long id){
        log.info("派送订单{}",id);
        orderService.delivery(id);
        return Result.success();
    }

    @GetMapping("/conditionSearch")
    @ApiOperation("管理端-获取订单信息")
    public Result<PageResult> queryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索{}",ordersPageQueryDTO);
        PageResult pageResult = orderService.queryPageInfo(ordersPageQueryDTO);
        return Result.success(pageResult);
    }


}
